package com.wanbangee.marksystem.controller;

import java.util.ArrayList;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.wanbangee.marksystem.analysisservice.QueryCurrentExamService;
import com.wanbangee.marksystem.service.ObjectiveOptionDistributionService;
import com.wanbangee.marksystem.service.QueryStuSubjectiveService;
import com.wanbangee.marksystem.service.QuerySubjectiveDistributionService;

@CrossOrigin
@RestController
@RequestMapping("/topicNoScoreInfo")
public class TestScoresDistributionController {

	@Autowired
	private ObjectiveOptionDistributionService objectiveOptionDistributionService;
	
	@Autowired
	private QueryCurrentExamService queryCurrentExamService;
	
	@Autowired
	private QueryStuSubjectiveService queryStuSubjectiveService;
	
	@Autowired
	private QuerySubjectiveDistributionService querySubjectiveDistributionService;
	
	@GetMapping("/selectOptionDistribution")
	public Map<String, Object> selectOptionDistribution(Integer examId,Integer subId,Integer claId,String topicNo){
		Map<String, Object> map = new HashMap<>();
		map.put("optionDistribution", this.objectiveOptionDistributionService.selectObjectOptionDistribution(examId, subId, claId, topicNo));
		return map;
	}
	
	@GetMapping("/selectStudentOption")
	public Map<String, Object> selectStudentOption(Integer examId, Integer subId, Integer claId, String topicNo,
			String option, String stuNmAndStuNo, Integer pageNum, Integer pageSize) {
		Map<String, Object> map = new HashMap<>();
		List<Map> stuOptionList = this.objectiveOptionDistributionService.selectObjectiveStudentOption(examId, subId, claId, topicNo, option, stuNmAndStuNo, pageNum, pageSize);
		map.put("studentOption",stuOptionList);
		map.put("totalStudentOption", stuOptionList.size());
		return map;
	}
	
	@GetMapping("/selectStuSubjective")
	public Map<String, Object> selectStuSubjective(Integer examId,Integer subId,String topicNo,Integer claId,
			Double minScore,Double maxScore,String stuNmOrStuNo,Integer pageNum,Integer pageSize){
		Map<String, Object> map = new HashMap<>();
		Integer scoreType = this.queryCurrentExamService.selectTopicScoreType(examId, subId, topicNo);
		if(scoreType == 1) {
			map.put("StuSubjectiveDetail", this.queryStuSubjectiveService.selectSubjectiveScoreSingleComment(examId, subId, topicNo, claId, minScore, maxScore, stuNmOrStuNo, pageNum, pageSize));
		}else if(scoreType == 2) {
			map.put("StuSubjectiveDetail", this.queryStuSubjectiveService.selectSubjectiveScoreMoreComment(examId, subId, topicNo, claId, minScore, maxScore, stuNmOrStuNo, pageNum, pageSize));
		}
		return map;
	}
	
	@GetMapping("/selectSubjectiveDistribution")
	public Map<String, Object> selectSubjectiveDistribution(Integer examId,Integer subId,Integer claId,String topicNo){
		Map<String, Object> map = new HashMap<>();
		List<Double> scoreList = new ArrayList<>();
		//查询该考试科目指定题目的分数
		Double topicScore = this.queryCurrentExamService.selectSubjectiveDistribution(examId, subId, topicNo);
		if(topicScore != null && topicScore != 0) {
			scoreList.add(topicScore/5);
			scoreList.add(topicScore*2/5);
			scoreList.add(topicScore*3/5);
			scoreList.add(topicScore*4/5);
			scoreList.add(topicScore);
			map.put("subDistribution", this.querySubjectiveDistributionService.selectSubjectiveDistribution(examId, subId, claId, topicNo, scoreList));
		}else {
			map.put("code", "10002");
			map.put("message", "找不到该页面");
		}
		return map;
	}
}
